//
//  QQGoodsAdressCell.m
//  QQZF
//
//  Created by hdz on 2018/7/2.
//  Copyright © 2018年 com.szqqkj. All rights reserved.
//

#import "QQGoodsAdressCell.h"
#import "HGAddressModel.h"

@implementation QQGoodsAdressCell {
    UILabel *_nameLabel;
    UILabel *_phoneLabel;
    UILabel *_adressLabel;
    UIButton *_defultBtn;
    UIButton *_editBtn;
    UIButton *_delBtn;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self initSubViews];
    }
    return self;
}

- (void)setModel:(HGAddressModel *)model {
    _model = model;
    _nameLabel.text = model.receivePerson;
    _phoneLabel.text = model.receiveTell;
    _adressLabel.text = [NSString stringWithFormat:@"%@%@%@%@",model.province,model.city,model.area,model.detail];
    _defultBtn.selected = model.isDefault;
}

- (void)initSubViews {
    
    CGFloat margin = 10;
    
    _nameLabel = [[UILabel alloc] init];
    _phoneLabel = [[UILabel alloc] init];
    _adressLabel = [[UILabel alloc] init];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = kColorBackground;
    
    _defultBtn = [[UIButton alloc] init];
    _defultBtn.tag = 999;
    [_defultBtn setTitle:@" 设为默认" forState:(UIControlStateNormal)];
    [_defultBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_defultBtn setTitleColor:[UIColor redColor] forState:(UIControlStateSelected)];
    [_defultBtn setImage:[UIImage imageNamed:@"oder-no"] forState:(UIControlStateNormal)];
    [_defultBtn setImage:[UIImage imageNamed:@"oder"] forState:(UIControlStateSelected)];
    _defultBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_defultBtn addTarget:self action:@selector(actionCilk:) forControlEvents:(UIControlEventTouchUpInside)];
    
    _editBtn = [[UIButton alloc] init];
    _editBtn.tag = 1000;
    [_editBtn setTitle:@" 编辑" forState:(UIControlStateNormal)];
    [_editBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    _editBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_editBtn addTarget:self action:@selector(actionCilk:) forControlEvents:(UIControlEventTouchUpInside)];
    
    _delBtn = [[UIButton alloc] init];
    _delBtn.tag = 1001;
    [_delBtn setTitle:@" 删除" forState:(UIControlStateNormal)];
    [_delBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    _delBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_delBtn addTarget:self action:@selector(actionCilk:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    [self.contentView addSubview:_nameLabel];
    [self.contentView addSubview:_phoneLabel];
    [self.contentView addSubview:_adressLabel];
    [self.contentView addSubview:lineView];
    [self.contentView addSubview:_defultBtn];
    [self.contentView addSubview:_editBtn];
    [self.contentView addSubview:_delBtn];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView).offset(margin);
    }];
    
    [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_nameLabel);
        make.left.equalTo(self.contentView).offset(150);
    }];
    
    [_adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_phoneLabel.mas_bottom).offset(margin);
        make.left.equalTo(_nameLabel);
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_adressLabel.mas_bottom).offset(margin);
        make.left.equalTo(_nameLabel);
        make.right.equalTo(self.contentView);
        make.height.offset(1);
    }];
    
    [_defultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nameLabel);
        make.top.equalTo(lineView.mas_bottom).offset(margin);
    }];
    
    [_delBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_defultBtn);
        make.right.equalTo(self.contentView).offset(-margin);
    }];
    
    [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_defultBtn);
        make.right.equalTo(_delBtn.mas_left).offset(-margin);
    }];
    
}


- (void)actionCilk:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(actionModel:withTag:)]) {
        [_delegate actionModel:_model withTag:sender.tag];
    }
}

@end
